#!/usr/bin/env python
import pygame

def silhouette(shape, color, aa=False):
    rect = pygame.Rect(shape.getRectangle())
    
    hurray = list(list([0, 0, 0, 0] for i in range(rect.height)) for i in range(rect.width))
    if aa:
        for x in range(rect.width*2):
            for y in range(rect.height*2):
                if shape.collidePoint(rect.left + x / 2.0, rect.top + y / 2.0):
                    hurray[x/2][y/2][0:3] = color
                    hurray[x/2][y/2][3] += 255 / 4
    else:
        for x in range(rect.width):
            for y in range(rect.height):
                if shape.collidePoint(rect.left + x, rect.top + y):
                    hurray[x][y][0:3] = color
                    hurray[x][y][3] = 255
    
    image = pygame.Surface(rect.size, pygame.SRCALPHA, 32)
    colorArray = pygame.surfarray.pixels3d(image)
    alphaArray = pygame.surfarray.pixels_alpha(image)
    for w in range(rect.width):
        for h in range(rect.height):
            colorArray[w][h][0:3] = hurray[w][h][0:3]
            alphaArray[w][h] = hurray[w][h][3]
    
    return image